<?php

use App\Http\Middleware\Merchant\PublicDeviceSignAuth;
use App\Kuafu\Common\Controller\B\UploadController;
use App\Kuafu\Config\Controller\Merchant\ConfigController;
use App\Kuafu\CouponPackage\Controller\Merchant\CouponPackageController;
use App\Kuafu\CustomerCoupon\Controller\Merchant\CustomerCouponController;
use App\Kuafu\Dashboard\Controller\Merchant\DashboardController;
use App\Kuafu\Mybank\Controller\Merchant\MybankController;
use App\Kuafu\Shop\Controller\Merchant\Outside\DeviceOutsideController;
use App\Kuafu\Shop\Controller\Merchant\ShopDistributionController;
use App\Kuafu\User\Enum\UserCodeEnum;
use Illuminate\Support\Facades\Route;
use App\Kuafu\Order\Controller\Merchant\OrderController;
use App\Kuafu\User\Controller\Merchant\LoginController;
use App\Kuafu\User\Controller\Merchant\UserController as MerchantUserController;
use App\Kuafu\Sms\Controller\Merchant\SmsController;
use App\Kuafu\Dashboard\Controller\Merchant\IndexController;
use App\Kuafu\Export\Controller\Merchant\ExportDownloadsController;
use App\Kuafu\Pay\Controller\Merchant\PayController;
use App\Kuafu\Product\Controller\Merchant\ProductController;
use App\Kuafu\Shop\Controller\Merchant\CameraController;
use App\Kuafu\Shop\Controller\Merchant\DeviceController;
use App\Kuafu\Shop\Controller\Merchant\ShopController;
use App\Kuafu\Shop\Controller\Merchant\ShopStatisticsController;
use App\Kuafu\Shop\Controller\Merchant\ToolsController;

//发送短信验证码
Route::post('sendSms', [SmsController::class, 'sendSms'])->middleware('customerThrottle:2,60');
// 检查手机号登录
Route::post('checkMobileLogin', [SmsController::class, 'checkMobileLogin']);

//获取版本强制更新信息
Route::get('appVersion', [ConfigController::class, 'getAppVersionInfo']);

//用户登录
Route::prefix('login')->group(function () {
    Route::post('/', [LoginController::class, 'login']);
    Route::post('/fs', [LoginController::class, 'fsLogin']);
    Route::post('/refresh', [LoginController::class, 'refresh']);
    Route::post('/forgetPassword', [MerchantUserController::class, 'forgetPassword']);
    Route::post('/netEaseDun', [LoginController::class, 'netEaseDun']);
});
Route::middleware(["jwtAuth:" . UserCodeEnum::MERCHANT_TYPE, 'merchantBrandShop', 'merchantUserPermission'])
     ->group(function () {

         // mqtt
         Route::prefix('mqtt')->group(function () {
             Route::get('/getAccount', [\App\Kuafu\Mqtt\Controller\Merchant\MqttController::class, 'getAccount']);
         });

         // 首页
         Route::prefix('dashboard')->group(function () {
             Route::get('/index', [IndexController::class, 'index']);
             //for 巡店
             Route::get('/cruise', [IndexController::class, 'index'])->withoutMiddleware([
                 "jwtAuth:" . UserCodeEnum::MERCHANT_TYPE,
                 'merchantBrandShop',
                 'merchantUserPermission'
             ]);
             Route::get('/permissionActions', [DashboardController::class, 'permissionActions']);
             Route::get('/bottomButtonShow', [DashboardController::class, 'bottomButtonShow']);
             Route::get('/indexCharts', [IndexController::class, 'indexCharts']);
         });

         // 用户中心
         Route::prefix('user')->group(function () {
             Route::post('/logout', [LoginController::class, 'logout']);
             Route::get('/', [MerchantUserController::class, 'getUserInfo'])->withoutMiddleware('merchantBrandShop');
             Route::get('/getUserInfoShopLists', [MerchantUserController::class, 'getUserInfoShopLists'])
                  ->withoutMiddleware('merchantBrandShop');
             Route::get('/getUserinfoWithShopAuth', [MerchantUserController::class, 'getUserinfoWithShopAuth'])
                  ->withoutMiddleware('merchantBrandShop');
             Route::post('/setUserInfo', [MerchantUserController::class, 'setUserInfo'])
                  ->withoutMiddleware('merchantBrandShop');
             Route::post('/setUserPassword', [MerchantUserController::class, 'setUserPassword']);
             Route::post('/setUserMobile', [MerchantUserController::class, 'setUserMobile']);
             Route::post('/verifyCode', [SmsController::class, 'verifyCode']);
             //绑定设备唯一ID
             Route::post('/binding', [MerchantUserController::class, 'bindingRegistrationId']);
             //编辑员工
             Route::post('setStaffInfo', [MerchantUserController::class, 'setStaffInfo']);
             Route::post('addStaffInfo', [MerchantUserController::class, 'addStaffInfo']);
             Route::get('getUserInfoByMobile', [MerchantUserController::class, 'getUserInfoByMobile']);
             Route::post('updateStatus', [MerchantUserController::class, 'updateStatus']); //调整员工状态
             Route::post('leaveEvaluate', [MerchantUserController::class, 'leaveEvaluate']); //离职员工评价

             // 健康证识别
             Route::post('healthCardOcr', [MerchantUserController::class, 'healthCardOcr']);
         });

         // 订单模块
         Route::prefix('order')->group(function () {
             Route::get('/combineOrderOverview', [OrderController::class, 'combineOrderOverview']);
             Route::get('/combineOrderChart', [OrderController::class, 'combineOrderChart']);
             Route::get('/combineOrderList', [OrderController::class, 'combineOrderList']);
             Route::get("/inOrderDetail/{id}", [OrderController::class, "inOrderDetail"])->where('id', '\d+');
             Route::get("/packageProductDetail", [OrderController::class, "packageProductDetail"]);
             Route::get('/waiMaiOrderDetail/{id}', [OrderController::class, "waiMaiOrderDetail"])->where('id', '\d+');

             Route::get('/divisionTimeStatistics', [OrderController::class, 'timeIntervalBusinessStatistics']);
             Route::get('/productSellStatistics', [OrderController::class, 'productSellStatistics']);
             Route::get('lastOperateTarget', [OrderController::class, 'getMonthActualIncome']);
         });

         //门店
         Route::prefix('shop')->group(function () {
             Route::get('getShopList', [ShopController::class, 'getShopList'])->withoutMiddleware('merchantBrandShop');
             Route::post('isCollectShop', [ShopController::class, 'isCollectShop'])
                  ->withoutMiddleware('merchantBrandShop');
             Route::post('setShopOperate', [ShopController::class, 'setShopOperate']);
             Route::get('getShopOperateDetail', [ShopController::class, 'getShopOperateDetail']);
             Route::get('getShopInfo', [ShopController::class, 'getShopInfo']);
             Route::post('setShopConfig', [ShopController::class, 'setShopConfig']);
             Route::get('getStaffList', [ShopController::class, 'getShopStaffList']);
             Route::get('getUserDetail', [ShopController::class, 'getUserDetail']);
             Route::get('getShopPositions', [ShopController::class, 'getShopPositions']);
             Route::get('shopList', [ShopController::class, 'shopList'])->withoutMiddleware('merchantBrandShop');

             // /shop/{shopId}/xxx
             Route::prefix('{shopId}')->group(function () {
                 Route::prefix('camera')->group(function () {
                     Route::get('/', [CameraController::class, 'index']);
                     Route::prefix('{id}')->group(function () {
                         // 摄像头详情
                         Route::get('/', [CameraController::class, 'info']);
                         // 心跳
                         Route::get('/heartBeat', [CameraController::class, 'heartBeat']);
                         // 摄像头状态
                         Route::get('/onlineStatus', [CameraController::class, 'onlineStatus']);
                         // 指定录像时间范围的录像文件播放地址。
                         Route::get('/record/date', [CameraController::class, 'queryLocalRecordDate']);
                         // 获取录像视频 url 根据时间段
                         Route::get('/record/play', [CameraController::class, 'queryDeviceVodUrlByTime']);

                         // ----- 停用接口
                         // 截图
                         Route::post('/picture', [CameraController::class, 'triggerCapturePicture']);
                         // 图片详情
                         Route::get('/picture/{captureId}', [CameraController::class, 'queryDevicePictureFile']);
                         // 视频开始录像
                         Route::post('/record/start', [CameraController::class, 'triggerRecord']);
                         // 视频结束录像
                         Route::post('/record/end', [CameraController::class, 'stopTriggeredRecord']);
                         // 本地录像上云
                         Route::post('/record/localUpload', [CameraController::class, 'createLocalFileUploadJob']);
                         // 查询本地录像上云 job 状态play
                         Route::get('/record/localUploadJob', [CameraController::class, 'queryLocalFileUploadJob']);
                         // 调用该接口通过录像文件ID查询录像文件
                         Route::get('/record/recordInfo', [CameraController::class, 'queryRecordByRecordId']);
                         // 根据云文件名称获取下载地址
                         Route::get('/record/downloadFile',
                             [CameraController::class, 'queryRecordDownloadUrlByFileName']);
                     });

                 });
             });
             Route::prefix('device')->group(function () {
                 // 查询监控人流量数据
                 Route::get('/getMonitorData', [DeviceController::class, "getMonitorData"]);
             });
             // 门店统计
             Route::prefix('statistics')->group(function () {
                 // 门店风云榜
                 Route::get('/windCloud', [ShopStatisticsController::class, 'getWindCloudRank'])
                      ->withoutMiddleware('merchantBrandShop');
             });

             // 渠道分销
             Route::prefix('distribution')->group(function () {
                 Route::post('/add', [ShopDistributionController::class, 'add']);
                 Route::put('/update/{id}', [ShopDistributionController::class, 'update'])->where('id', '\d+');
                 Route::get('/info/{id}', [ShopDistributionController::class, 'info'])->where('id', '\d+');
                 Route::get('/list', [ShopDistributionController::class, 'list']);
//                 Route::delete('/delete/{id}', [ShopDistributionController::class, 'delete'])->where('id', '\d+');
                 Route::put('/updateStatus/{id}', [ShopDistributionController::class, 'updateStatus'])
                      ->where('id', '\d+');
                 Route::get('/historyBillList', [ShopDistributionController::class, 'historyBillList']);
                 Route::get('/genDistributionOrderCode',
                     [ShopDistributionController::class, 'genDistributionOrderCode']);
                 Route::get('/searchList', [ShopDistributionController::class, 'searchList']);
             });
         });

         // 支付
         Route::prefix('pay')->group(function () {
             Route::get('lists', [PayController::class, 'lists']);
             Route::get('listsStatistics', [PayController::class, 'listsStatistics']);
             Route::get('listsFilter', [PayController::class, 'listsFilter']);
             Route::get('detail', [PayController::class, 'detail']);
             Route::get('groupStatistics', [PayController::class, 'groupStatistics']);

             Route::get('listsNew', [PayController::class, 'listsNew']);
             Route::get('listsStatisticsNew', [PayController::class, 'listsStatisticsNew']);
             Route::get('groupStatisticsNew', [PayController::class, 'groupStatisticsNew']);
         });

         // 会员收入
         Route::prefix('vipIncome')->group(function () {
             Route::get('lists', [CouponPackageController::class, 'lists']);
             Route::get('listsStatistics', [CouponPackageController::class, 'listsStatistics']);
             Route::get('listsFilter', [CouponPackageController::class, 'listsFilter']);
             Route::get('detail', [CouponPackageController::class, 'detail']);
         });

         // 菜品销售统计
         Route::prefix('productSales')->group(function () {
             Route::get('shopProducts', [ProductController::class, 'shopProducts']);
             Route::get('shopCategories', [ProductController::class, 'shopCategories']);
             Route::post('inOrderStatistics', [ProductController::class, 'inOrderStatistics']);
             Route::post('waiMaiOrderStatistics', [ProductController::class, 'waiMaiOrderStatistics']);
         });

         // 套餐新增
         Route::prefix('product')->group(function () {
             Route::get("/ordinaryProducts", [ProductController::class, 'ordinaryProducts']);//获取菜品列表
             Route::get('/lists', [ProductController::class, 'lists']); // 店铺下的菜单、菜品、分类列表
             Route::post('/', [ProductController::class, 'insert']); // 店铺下的菜单、菜品、分类列表
             Route::patch('/{productId}', [ProductController::class, 'status']); // 状态修改
             Route::put('/{productId}', [ProductController::class, 'update']); //更新菜品信息
             Route::get('/{productId}', [ProductController::class, 'detail']);//菜品详情
             Route::delete('/{productId}', [ProductController::class, 'delete']);//菜品删除

             // 价签生成导出
             Route::post('/priceTagGenerate', [ProductController::class, 'priceTagGenerate']);
         });

         // 手机工具箱
         Route::prefix('tools')->group(function () {
             Route::prefix('waimai')->group(function () {
                 Route::get('/evaluateCardDemo', [ToolsController::class, 'getWaiMaiPicDemo']);
                 Route::post('/evaluateCardGen', [ToolsController::class, 'genWaiMaiPic']);
             });
             // 物料素材模版
             Route::prefix('sourceMaterialTemplate')->group(function () {
                 Route::get('list', [ToolsController::class, "list"]);
                 Route::get('detail/{id}', [ToolsController::class, "detail"])->where('id', '\d+');
                 Route::post('create/{id}', [ToolsController::class, "create"])->where('id', '\d+');
                 Route::get('typeConfig', [ToolsController::class, "typeConfig"]);
             });
         });

         // 店铺结算（日结单）
         Route::get('/calcShopTrade', [OrderController::class, 'calcShopTrade']);

         //商家App banner图列表
         Route::get('getAppBanner', [\App\Kuafu\Banner\Controller\Internal\BannerController::class, 'index']);

         // 门店设备
         Route::prefix("device")->group(function () {
             Route::get("config", [CameraController::class, "config"]);//设备配置
             Route::get("shopTv", [CameraController::class, "shopTv"]);//门店设备信息
             Route::post("bind", [CameraController::class, "bind"]);//设备绑定
             Route::post("rmBind", [CameraController::class, "rmBind"]);//设备移除
             Route::get("bannerSearch", [CameraController::class, "bannerSearch"]);//广告素材搜索
             Route::get("bannerConfig", [CameraController::class, "bannerConfig"]);//广告位置查询是否系统配置了图片
             Route::get("/{id}", [CameraController::class, "detail"])->where('id', '\d+');//设备详情
             Route::post("/{id}", [CameraController::class, "update"])->where('id', '\d+');//设备编辑
             Route::get("bannerSearchById/{id}", [CameraController::class, "bannerSearchById"])
                  ->where('id', '\d+');//广告素材组合单个搜索

         });

         //用户优惠券
         Route::prefix("customerCoupon")->group(function () {
             Route::get("usedList", [CustomerCouponController::class, "usedList"]);//已核销列表
             Route::post("use", [CustomerCouponController::class, "use"])->middleware('customerThrottle:1,2');//优惠券核销
             Route::post("checkCoupon", [CustomerCouponController::class, "checkCoupon"])
                  ->middleware('customerThrottle:1,2');//优惠券核销
             Route::post("cancelUse", [CustomerCouponController::class, "cancelUse"])
                  ->middleware('customerThrottle:1,2');//优惠券撤销核销
             Route::get("detail", [CustomerCouponController::class, "detail"]);//优惠券详情
             Route::get("detailInfo", [CustomerCouponController::class, "detailInfo"]);//优惠券详情v2
         });

         // 导出报表-下载清单记录
         Route::prefix('exportDownloads')->group(function () {
             Route::get("/", [ExportDownloadsController::class, "lists"]);
             Route::delete("/{id}", [ExportDownloadsController::class, "delete"]);
             Route::post('export', [ExportDownloadsController::class, "export"]);
         });

         // 钱包
         Route::prefix('mybank')->group(function () {
             Route::get("wallet", [MybankController::class, "wallet"]);//钱包明细
             Route::get("addClickLog", [MybankController::class, "addClickLog"]);//添加查看日志
             Route::get('billList', [MybankController::class, "billList"]);//账单明细列表
             Route::get('billDetail/{id}', [MybankController::class, "billDetail"])->where('id', '\d+');//账单明细详情
         });

         // 文件上传
         Route::prefix('upload')->group(function () {
             Route::post('images', [UploadController::class, 'ImagesUploads']);
         });
     });

Route::prefix('public/device')->group(function () {
    Route::post('/adv', [CameraController::class, 'deviceAdv']);//设备广告
});

Route::middleware([PublicDeviceSignAuth::class])->prefix('/public/shop/device')->group(function () {

    // 获取设备绑定状态+设备信息+MQ账号
    Route::post('getDeviceInfo', [DeviceOutsideController::class, 'getDeviceInfo']);
    // 获取素材列表
    Route::post('getDeviceMaterial', [DeviceOutsideController::class, 'getDeviceMaterial']);

    Route::post('/adv', [CameraController::class, 'deviceAdv']);//设备广告
    Route::post('/getMQTTAccount', [DeviceOutsideController::class, 'getMQTTAccount']);//设备广告 -- 接口作废
    Route::post('/getDeviceConfig', [DeviceOutsideController::class, 'getDeviceConfig']);//获取设备配置 -- 接口作废
    Route::post('/mergeImageFace', [DeviceOutsideController::class, 'mergeImageFace']);//图片合成
    Route::get('/mergeImageTemplate', [DeviceOutsideController::class, 'mergeImageTemplate']);//图片合成
});
